﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;
using IntelligentDecisioning.SharePoint.Repositories;
using IntelligentDecisioning.SharePoint.BusinessEntities;
using IntelligentDecisioning.SharePoint.Shared;
using Microsoft.Practices.SPG.Common.ServiceLocation;
using IntelligentDecisioning.SharePoint.repositories;

namespace TestIDSharePoint
{
    /// <summary>
    /// Console app utility to test id-sharepoint
    /// </summary>
    public class Program
    {
        static void Main(string[] args)
        {

            IDSharePointContext context = new IDSharePointContext();
            context.SiteCollectionUrl = "http://rdmis/studies/37";
            //context.SiteCollectionUrl = "http://rdmis/sites/test";
            context.UseRootWeb = true;


            ////// SharePoint task extension list
            //IListItemRepository<SharePointProjectTaskEntity> projectTaskExtensionRepository = new ListItemRepository<SharePointProjectTaskEntity>();
            //projectTaskExtensionRepository.InitialiseRepository("Demo Project Task Extension List", context);

            //List<SharePointProjectTaskEntity> projectTaskExtensions = projectTaskExtensionRepository.GetEntities();

            //foreach (SharePointProjectTaskEntity projectTaskExtension in projectTaskExtensions)
            //{
            //    Console.WriteLine(projectTaskExtension.Id.ToString());
            //    Console.WriteLine(projectTaskExtension.Title);
            //    Console.WriteLine(projectTaskExtension.Created.ToString());
            //    Console.WriteLine(projectTaskExtension.LastModified.ToString());
            //    Console.WriteLine(projectTaskExtension.Author);
            //    Console.WriteLine(projectTaskExtension.Editor);
            //    Console.WriteLine(projectTaskExtension.AssignedTo);
            //    Console.WriteLine(projectTaskExtension.Body);
            //    Console.WriteLine(projectTaskExtension.Status);
            //    Console.WriteLine(projectTaskExtension.PercentComplete);
            //}

            // SharePoint task list
            IListItemRepository<SharePointProjectTaskEntity> projectTaskRepository = new ListItemRepository<SharePointProjectTaskEntity>();
            projectTaskRepository.InitialiseRepository("Demo Project Task List", context);

            List<SharePointProjectTaskEntity> projectTasks = projectTaskRepository.GetEntities();

            foreach (SharePointProjectTaskEntity projectTask in projectTasks)
            {
                Console.WriteLine(projectTask.Id.ToString());
                Console.WriteLine(projectTask.Title);
                Console.WriteLine(projectTask.Created.ToString());
                Console.WriteLine(projectTask.LastModified.ToString());
                Console.WriteLine(projectTask.Author);
                Console.WriteLine(projectTask.Editor);
                Console.WriteLine(projectTask.AssignedTo);
                Console.WriteLine(projectTask.Body);
                Console.WriteLine(projectTask.Status);
                Console.WriteLine(projectTask.PercentComplete);
            }

            // Custom List
            IListItemRepository<ListItemEntityBase> listItemRepository = new ListItemRepository<ListItemEntityBase>();
            listItemRepository.InitialiseRepository("test", context);

            List<ListItemEntityBase> items = listItemRepository.GetEntities();
            foreach (ListItemEntityBase item in items)
            {
                Console.WriteLine(item.Id.ToString());
                Console.WriteLine(item.Title);
                Console.WriteLine(item.Created.ToString());
                Console.WriteLine(item.LastModified.ToString());
                Console.WriteLine(item.Author);
                Console.WriteLine(item.Editor);
            }

            // SharePoint task list
            IListItemRepository<SharePointTaskEntity> taskRepository = new ListItemRepository<SharePointTaskEntity>();
            taskRepository.InitialiseRepository("Demo Task List", context);

            List<SharePointTaskEntity> tasks = taskRepository.GetEntities();
           
            foreach (SharePointTaskEntity task in tasks)
            {
                Console.WriteLine(task.Id.ToString());
                Console.WriteLine(task.Title);
                Console.WriteLine(task.Created.ToString());
                Console.WriteLine(task.LastModified.ToString());
                Console.WriteLine(task.Author);
                Console.WriteLine(task.Editor);
                Console.WriteLine(task.AssignedTo);
                Console.WriteLine(task.Body);
                Console.WriteLine(task.Status);
                Console.WriteLine(task.PercentComplete);
            }



            //IDemonstrationTaskRepository repTask = SharePointServiceLocator.Current.GetInstance<IDemonstrationTaskRepository>();
            //foreach (DemonstrationTaskEntity task in repTask.GetTasks(context))
            //{
            //    Console.WriteLine(task.Status);
            //    Console.WriteLine(task.AssignedTo);
            //}


            ////typeMappings.RegisterTypeMapping<IDemonstrationDocumentLibraryRepository, DemonstrationDocumentLibraryRepository>();
            //IDemonstrationDocumentLibraryRepository docRepository = SharePointServiceLocator.Current.GetInstance<IDemonstrationDocumentLibraryRepository>();
            //foreach (DemonstrationDocumentLibraryEntity entity in docRepository.GetDocuments(context))
            //{
            //    Console.WriteLine(entity.Title);
            //}
            Console.ReadLine();
        }
    }
}
